<template>
  <a-card class="info" title="工作流测试">
      <template slot="extra">
        <template v-if="model.bpmStatus==='1'">
            <a-icon type="edit" theme="twoTone" :style='iconStyle' @click="handleEdit(model)"/>
            <a-divider type="vertical"/>
            <a-button type="primary" size="small" @click="startProcess(model)">发起流程</a-button>
        </template>
      </template>
     <a-row type="flex"  justify="center">
       <a-col :span="16">
          <test-bpm-form ref="realForm" :disabled="true" normal></test-bpm-form>
       </a-col>
     </a-row>
     <test-bpm-modal ref="modalForm" @ok="modalFormOk"></test-bpm-modal>
  </a-card>
</template>

<script>

import {getAction, postAction} from '@/api/manage'
import TestBpmForm from './modules/TestBpmForm2'
import TestBpmModal from './modules/TestBpmModal'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'


export default {
    name: 'TestBpmDetail',
    mixins: [JeecgListMixin],
    components: {
     TestBpmForm,
     TestBpmModal
    },
    data () {
      return {
         model: {},
        id: '',
        url: {
          queryById: "/test/testBpm/queryById",
          delete: "/test/testBpm/delete",
          startProcess: '/api/erpmng/act/process/extActProcess/startMutilProcess'
        },
        confirmLoading: false,
        iconStyle:{"font-size":"20px"},
        //代码生成后需手动设置流程编码
        flowCode: 'dev_test_bpm_001',
      }
    },
    created() {
    },
    watch: {
      $route(to, from) {
        this.loadData();
      },
    },
    mounted() {
    },
    methods: {
      loadData() {
        const id = this.$route.params.id;
        getAction(this.url.queryById, { id }).then((res) => {
          if (res.success) {
            const model = res.result
            this.$refs.realForm.edit(model);
            this.model=model;
          }
        })
      },
      startProcess(record){
        this.$confirm({
          title:'提示',
          content:'确认提交流程吗?',
          onOk:()=>{
            let params = {
              flowCode: this.flowCode,
              id: record.id,
              formUrl: 'test/modules/TestBpmForm',
              formUrlMobile: ''
            }
            postAction(this.url.startProcess, params).then(res=>{
              if(res.success){
                this.$message.success(res.message);
                this.loadData();
                this.onClearSelected();
              }else{
                this.$message.warning(res.message);
              }
            }).catch((e)=>{
              this.$message.warning('不识别的请求!');
            })
          }
        })
      },
    }
  }
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';

.info {
  /deep/ .ant-card-head-title{
    flex: none;
    margin-right: 20px;
  }
  /deep/ .ant-card-extra{
    flex: 1;
    float: left;
  }
}
</style>
